// custom-tab-bar/index.js
import {
  createStoreBindings
} from 'mobx-miniprogram-bindings'
import {
  store
} from '../store/index.js'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
  },

  /**
   * 组件的初始数据
   */
  data: {
    value: 0,
    top: 0,
    tabBer: [
      {
        pagePath: '/pages/index/index',
        text: '首页',
        iconPath: '/images/taber/info_no.png',
        selectedIconPath: '/images/taber/home_yes.png'
      },
      {
        pagePath: '/pages/class/index',
        text: '消息',
        iconPath: '/images/taber/info_no.png',
        selectedIconPath: '/images/taber/info_yes.png'
      },
      {
        pagePath: '/pages/share/index',
        text: '好物',
        iconPath: '/images/taber/z_no.png',
        selectedIconPath: '/images/taber/z_yes.png'
      },
      {
        pagePath: '/pages/cart/index',
        text: '购物车',
        iconPath: '/images/taber/cart_no.png',
        selectedIconPath: '/images/taber/cart_yes.png'
      },
      {
        pagePath: '/pages/my/index',
        text: '我的',
        iconPath: '/images/taber/my_no.png',
        selectedIconPath: '/images/taber/my_yes.png'
      }
    ]
  },
  lifetimes: {
    ready: function () {
      this.storeBindings = createStoreBindings(this, {
        // 属性
        store,
        fields: [
          "tabBerActive",
          "top",
        ],
        actions: [
          "addCount"
        ]
      })
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      this.addCount(event.detail)
      console.log(event.detail);
      switch (event.detail) {
        case 0:
          wx.switchTab({
            url: '/pages/index/index',
          })
          break;
        case 1:
          wx.switchTab({
            url: '/pages/class/index',
          })
          break;
        case 2:
          wx.switchTab({
            url: '/pages/share/index',
          })
          break;
        case 3:
          wx.switchTab({
            url: '/pages/cart/index',
          })
          break;
        case 4:
          wx.switchTab({
            url: '/pages/my/index',
          })
      }
    },
  },
})
